﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.ApplicationServices;

namespace Galaxy.AutoCAD.Databases
{
    public static class TextStyleTool
    {
        #region 通过文字样式名获得文字样式id
        public static ObjectId GetTextStyleId(string textStyleName)
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            ObjectId result = ObjectId.Null;
            using (Transaction tran = db.TransactionManager.StartTransaction())
            {
                TextStyleTable tst = tran.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                if (tst.Has(textStyleName))
                {
                    result = tst[textStyleName];
                }
                tran.Commit();
            }
            return result;
        }
        #endregion
    }
}
